Use of...

Search
Other Bug Reports questions
Forum

Use of {source} <?php require_once('.... causes an error in Smart Search

Eric de Waal's Avatar Eric de Waal
Hi Peter,

If an article contains:
{source}
 <?php require_once('..../rittenscan/mijn_gescande_ritten.php')

then building an index will abort as soon as the article is processed: error:

Failed opening required '..../rittenscan/mijn_gescande_ritten.php' (include_path='.:/usr/local/lib/php/')

If I replace require_once by include_once then Smart Search buids it's index without problems.

Hope you can fix it!

Best regards,
Eric
Peter van Westen's Avatar Peter van Westen ADMIN
There is nothing to fix on my side.
Tge issue is with you're code. The syntax is wrong, mainly the '....' part.
Please read: docs4.regularlabs.com/sourcerer/the-basics/including-files
Please post a rating at the Joomla! Extensions Directory
Eric de Waal's Avatar Eric de Waal
Him

The '....' part stands for the rest of the relative path from my site root, I did not show it here but the complete statement could be like this:
require_once ('mylibfolder/rittenscan/mijn_gescande_ritten.php').
Like a relative path for an image in an article. That code works from the front end.
I added JPATH_SITE . and called from the front end that still works.

But now the indexer gives a different error:

An Error Has Occurred
The following message was returned by the server:
An error has occurred while fetching the JSON data: HTTP 1146 status code.
Peter van Westen's Avatar Peter van Westen ADMIN
Most probably this is down to something in the PHP of that file.
See if the indexer does work if you replace the content of that file with something simple, like:
<?php echo 'test';
Please post a rating at the Joomla! Extensions Directory
Eric de Waal's Avatar Eric de Waal
I'm sorry Peter, but even with:
<?php echo 'test';
in the required_once file the indexer stops with an error:

An Error Has Occurred
The following message was returned by the server:
A parse error has occurred while processing the following JSON data:
JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

If I use 'include' in stead of 'required' the indexer finishes but contains errors for each article that uses {source} to include files.
Peter van Westen's Avatar Peter van Westen ADMIN
Can you give me (super) admin and (s)ftp access so I can take a look?

You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
Eric de Waal's Avatar Eric de Waal
Confidential information:
(hidden)
Eric de Waal's Avatar Eric de Waal
Hi Peter,

Indeed it has to do with the content of the files that I include.
When executed from the indexer, certain user input is missing and variables not filled.
This occurrs in about half of my articles with sourcerer. The other half get indexed without problems.
So it is not a problem of sourcerer and I will have to set some default values for missing input.
Thanks for your support!

Best,
Eric

Edit: unfortunately there seems to be no way to exclude articles from being indexed on beforehand, only filtering afterwards.
Edit 2: and the indexer is really picky. If it meets a 'die()' statement it already gives an indexing error.
Edit 3: for people who run into the same problem.
As said above; the indexer really EXECUTES the code that you inserted via sourcerer.
That means: it should not generate errors even when variables have not been set because it will halt the indexer.
AND it might lead to unexpected reults; in my case the indexer sent a handful of emails that were supposed to be sent when the article was openend!
Peter van Westen's Avatar Peter van Westen ADMIN
Happy you found the cause of the issue.
Please post a rating at the Joomla! Extensions Directory
You can only post on this forum if you log in